# 圆角窗体+ QWebEngineView(纯展示数据类型的web)+在上面盖一层label以达到支持拖动效果

from PyQt5.QtWidgets import QApplication, QMainWindow ,QWidget,QLabel
from PyQt5.QtCore import Qt, QUrl ,QRectF
from PyQt5.QtGui import QPainter, QPen, QBrush, QColor, QRegion, QPainterPath 
from PyQt5.QtWebEngineWidgets import QWebEngineView

class RoundedWindow(QMainWindow):  
    def __init__(self):  
        super().__init__()  
        self.initUI()  
  
    def initUI(self):  
        # 设置为无边框窗口  
        self.setWindowFlags(Qt.FramelessWindowHint) 
        self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明

          
        # 创建一个QWebEngineView实例  
        self.browser = QWebEngineView(self)  
        # 加载网页  
        self.browser.load(QUrl("https://www.baidu.com"))  
        # 设置初始大小和位置（可选）  
        self.setGeometry(100, 100, 800, 600)  
        # 设置QWebEngineView的大小以适应窗口内部（不包括圆角部分）  
        # 假设圆角的半径为10  
        self.browser.setGeometry(10, 10, self.width() - 20, self.height() - 20)

        central_widget = QWidget(self)  
        self.setCentralWidget(central_widget)  
        label = QLabel("PyQt5 Desktop QMainWindow!",central_widget)
        # 设置字体和颜色（使用样式表）  
        label.setStyleSheet("""  
            QLabel {  
                font-family: Arial;  
                font-size: 14pt;  
                font-weight: bold;  
                color: green;
                background-color: rgba(0, 0, 200, 200); 
            }  
        """) 
        label.setGeometry(10, 5, self.width() - 20, 35)
  
    def paintEvent(self, event):  
        painter = QPainter(self)  
        painter.setRenderHint(QPainter.Antialiasing)  
  
        # 绘制圆角矩形背景  
        pen = QPen(Qt.NoPen)  
        brush = QBrush(QColor(255, 255, 255))  # 设置背景颜色  
        painter.setPen(pen)  
        painter.setBrush(brush)  
        rect = self.rect()  
        rect.adjust(5, 5, -5, -5)  # 根据需要调整圆角大小  
        path = QPainterPath()  
        path.addRoundedRect(QRectF(rect) , 10, 10)  # 圆角半径为10  
        painter.drawPath(path) 

    def mousePressEvent(self, event):  
        # 当鼠标按下时记录位置，用于后续拖动窗口  
        self.drag_position = event.globalPos() - self.frameGeometry().topLeft()  
  
    def mouseMoveEvent(self, event):  
        # 当鼠标移动时，如果左键被按下，则移动窗口  
        if event.buttons() == Qt.LeftButton:  
            self.move(event.globalPos() - self.drag_position)  
            event.accept()   
  
if __name__ == '__main__':  
    import sys  
    app = QApplication(sys.argv)  
    window = RoundedWindow()  
    window.show()  
    sys.exit(app.exec_())